import { AdjustHeader, AdjustTable, ExecuteModal } from './components';
import Store from './Store';
import { LIST_NAME, EXECUTE_RECORD_LIST_NAME } from './constants';

export default {
  components: {
    AdjustHeader,
    AdjustTable,
    ExecuteModal,
  },
  metaInfo: {
    title: '分时段调价记录页面',
  },
  data() {
    return {
      store: new Store([
        { listName: LIST_NAME, pageSize: 10 },
        { listName: EXECUTE_RECORD_LIST_NAME, pageSize: 10 },
      ]),
    };
  },
  computed: {
    ...['list'].reduce(
      (prev, curr) => ({
        ...prev,
        [curr]: {
          get() {
            if (curr === 'list') {
              const { data = [], ...restParams } = this.store[curr][LIST_NAME];
              return {
                ...restParams,
                data,
              };
            }
            return this.store[curr];
          },
        },
      }),
      {},
    ),
    executeModalProps() {
      const {
        list: {
          [EXECUTE_RECORD_LIST_NAME]: { data = [], ...restListParams },
        },
        executeModalValues: { visible },
      } = this.store;
      return {
        ...restListParams,
        data,
        visible,
      };
    },
  },
  methods: {
    ...[
      'init',
      'onHeaderQuery',
      'onHeaderReset',
      'onTablePageSizeChange',
      'onTablePageNumChange',
      'onTableRowRecord',
      'onTableRowTaskCancel',
      'onExecuteModalClose',
      'onExecuteModalOpen',
      'onExecuteModalQuery',
      'onExecuteModalReset',
      'onExecuteModalPageNumChange',
      'onExecuteModalPageSizeChange',
      'onExecuteModalDownErrorFile',
    ].reduce(
      (prev, curr) => ({
        ...prev,
        [curr](args) {
          this.store[curr](args);
        },
      }),
      {},
    ),
  },
  mounted() {
    this.store.init();
  },
};
